import api from './auth';

// 获取当前登录用户的详细信息
export const getUserInfo = () => {
  return api.get('/user/info');
};

// 更新用户信息
export const updateUserInfo = (data) => {
  return api.put('/user/update', data);
};

// 修改密码
export const changePassword = (passwordData) => {
  return api.put('/user/password', passwordData);
};

// 获取用户评论列表
export const getUserComments = (params) => {
  return api.get('/user/comments', { params });
};

// 获取用户收藏列表
export const getUserFavorites = (params) => {
  return api.get('/user/favorites', { params });
};

// 上传用户头像
export const uploadAvatar = (formData) => {
  return api.post('/user/avatar', formData, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
};

// 删除用户评论
export const deleteUserComment = (commentId) => {
  return api.delete(`/user/comments/${commentId}`);
};

// 取消收藏
export const removeFavorite = (attractionId) => {
  return api.delete(`/user/favorites/${attractionId}`);
};

// 根据用户ID获取用户详细信息
export const getUserById = (userId) => {
  return api.get(`/user/${userId}`);
};

// 验证用户身份（忘记密码流程）
export const verifyIdentity = async (data) => {
  try {
    const response = await api.post('/password/verify-identity', data);
    return response;
  } catch (error) {
    console.error('验证用户身份请求失败:', error);
    throw error;
  }
};

// 重置密码
export const resetPassword = async (data) => {
  try {
    const response = await api.post('/password/reset-password', data);
    return response;
  } catch (error) {
    console.error('重置密码请求失败:', error);
    throw error;
  }
};

// 获取用户列表
export const getUserList = (params) => {
  return api.get('/admin/user/list', { params });
};

// 更新用户信息
export const updateUser = (userId, data) => {
  return api.put(`/admin/user/${userId}`, data);
}; 